<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let money = 0;
        let year = 0;
        let promise = new Promise((resolve,reject) => {
            while(money<20) {
                year++
                var m = Math.round(Math.random()*10)
                money += m
                console.log('男主第'+ year +'年赚了'+ money +"w元");
            }
            if(year>4) {
                resolve('童话里都是美好的')
            } else {
                reject('童话故事结局')
            }
        })
        promise.then( (resolve) => {
            console.log(resolve);
        })
        .catch((reject) => {
            console.log(reject);
        }) 
    </script>
</body>
</html>